package com.yypx.service.impl;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.yypx.common.utils.ObjToMapUtil;
import com.yypx.dao.StudentTypeDAO;
import com.yypx.entity.StudentType;
import com.yypx.service.StudentTypeService;

@Component("studentTypeService")
public class StudentTypeServiceImpl implements StudentTypeService {
	@Autowired
	private StudentTypeDAO studentTypeDAO;

	@Override
	public void add(StudentType studentType) {
		studentTypeDAO.addNew(studentType);
	}

	@Override
	public void delete(Integer tid) {
		studentTypeDAO.delById(tid);
	}

	@Override
	public StudentType findById(Integer tid) {
		return studentTypeDAO.findById(tid);
	}

	@Override
	public List<StudentType> selAll() {
		return studentTypeDAO.selAll();
	}

	@Override
	public void update(StudentType studentType) {
		studentTypeDAO.update(studentType);
	}

	@Override
	public List<Map<String, Object>> getResultList(List<StudentType> list) {
		if (list == null)
			return null;
		List<Map<String, Object>> result = new ArrayList<Map<String, Object>>();
		for (int i = 0; i < list.size(); i++) {
			HashMap<String, Object> resultItem = (HashMap<String, Object>) ObjToMapUtil.toHashMap(list.get(i));
			/* 在这个地方可以根据具体的情况对实体的属性的页面返回做处理，比如说1代表可用 ，0代表不可用 */
			handleEntityForPageTemplate(resultItem, list.get(i));
			result.add(resultItem);
		}
		return result;
	}

	@Override
	public void handleEntityForPageTemplate(Map<String, Object> map, StudentType studentType) {
		// TODO createdby 取创建者名称
	}

	@Override
	public Map<String, Object> getResultMap(StudentType sType) {
		HashMap<String, Object> resultItem = (HashMap<String, Object>) ObjToMapUtil.toHashMap(sType);
		/* 在这个地方可以根据具体的情况对实体的属性的页面返回做处理，比如说1代表可用 ，0代表不可用 */
		handleEntityForPageTemplate(resultItem, sType);
		return resultItem;
	}
}
